//
//  ProgressView.m
//  IOSUI思路
//
//  Created by 崔博 on 2018/9/26.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "ProgressView.h"
#import "ProgressLabyer.h"
@implementation ProgressView

+ (Class) layerClass
{
    return [ProgressLabyer class];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        // 初始化变量
        [self initVars];
    }
    return self;
}

- (void)initVars
{
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;
    self.tinColor = [UIColor colorWithRed:.2 green:.45 blue:.8 alpha:1.0];
    self.trackColor = [UIColor whiteColor];
}

- (void)setProress:(float)proress animated:(BOOL)animated
{
    ProgressLabyer * layer = (ProgressLabyer *)self.layer;
    if (proress < 0) {
        proress = 0;
    }else if(proress > 1){
        proress = 1;
    }
    if (animated) {
        CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"progress"];
        ani.duration = 0.25;
        ani.fromValue = [NSNumber numberWithFloat:layer.proress];
        ani.toValue = [NSNumber numberWithFloat:proress];
        [layer addAnimation:ani forKey:@""];
        layer.proress = proress;
    }else
    {
        layer.proress = proress;
        [layer setNeedsDisplay];
    }
}
- (void)setTinColor:(UIColor *)tinColor
{
    ProgressLabyer * layer = (ProgressLabyer *)self.layer;
    layer.tinColor = tinColor;
    [layer setNeedsDisplay];
}
- (void)setTrackColor:(UIColor *)trackColor
{
    ProgressLabyer * layer = (ProgressLabyer *)self.layer;
    layer.tinColor = trackColor;
    [layer setNeedsDisplay];
}
- (void)setStartAngle:(float)startAngle
{
    ProgressLabyer * layer = (ProgressLabyer *)self.layer;
    layer.startAngle = startAngle;
    [layer setNeedsDisplay];
}
- (float)startAngle
{
    ProgressLabyer * layer = (ProgressLabyer *)self.layer;
    return layer.startAngle;
}
@end
